<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

namespace app\controller\admin\v1\recruit;

use app\controller\admin\AuthController;
use app\model\other\CityArea;
use app\model\store\DeliveryService;
use app\model\user\User;
use app\model\v1\recovery\ConfigAbout;
use app\model\v1\recovery\RecoveryQuestionCate;
use app\model\v1\recovery\RecoveryReport;
use app\model\v1\recovery\SystemOperationLog;
use app\model\v1\recruit\RecruitCompany;
use app\model\v1\recruit\RecruitIndustry;
use app\model\v1\recruit\RecruitJob;
use app\model\v1\recruit\RecruitJobCate;
use app\model\v1\recruit\RecruitJobSeeker;
use app\model\v1\recruit\RecruitLanguage;
use app\model\v1\recruit\RecruitPersonageAuthentication;
use app\model\v1\recruit\RepairSuggestion;
use app\model\v1\repair\AuxiliaryMaterialData;
use app\model\v1\repair\Construction;
use app\model\v1\repair\Maintenance;
use app\model\v1\repair\MaintenanceOrder;
use app\model\v1\repair\RepairCat;
use app\model\v1\repair\RepairCatUser;
use app\model\v1\repair\RepairConsult;
use app\model\v1\repair\RepairService;
use app\model\v1\repair\SurveyorService;
use app\model\v1\repair\UserPosition;
use app\model\v1\repair\UserWork;
use app\model\v1\repair\WorkerExamine;
use app\model\v1\repair\WorkType;
use app\Request;
use app\services\article\ArticleCategoryServices;
use crmeb\services\CacheService;
use think\facade\App;
use think\facade\Db;
use think\filesystem\driver\Local;

/**
 * 快修后台管理
 * Class ArticleCategory
 * @package app\controller\admin\v1\cms
 */
class RepairCollection extends AuthController
{
    protected $model;

    public function __construct(App $app, RecruitJobSeeker $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }



    /**
     * 快修后台 - 获取员工管理列表
     * @return mixed
     */
    public function getUserPositionList (Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = UserPosition::getUserPositionList($param);
        return $this->success($data);
    }


    /**
     * 获取工种
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWorkTypeCat(Request $request)
    {
        $type = 1;
        if (input ('?type')){
            $type = input ('type','2');
        }
        $data = Db::name('work_type')->where ('status',1)->where('type',$type)->field ('id,name')->select();

        return $this->success($data ? $data->toArray() : []);
    }


    /**
     * 员工管理列表 - 新增
     * @return false|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function user_authority()
    {
        $result = [
            'status' => false,
            'data' => '',
            'msg' => ''
        ];
        if (!input("?param.authority_id")) {
            $result['msg'] = '工人类型不能为空';
            return json_encode($result);
        }
        if (!input("?param.name")) {
            $result['msg'] = '员工姓名不能为空';
            return json_encode($result);
        }
        if (!input("?param.phone_number")) {
            $result['msg'] = '手机号输入错误请重新输入';
            return json_encode($result);
        }
        $user = Db::name('user')->where('uid',input("param.user_id"))->find();
        if (!$user){
            $result['msg'] = '用户不存在';
            return json_encode($result);
        }
        $res = Db::name('user_position')->where ('user_id',$user['uid'])->find ();
        if ($res){
            $result['msg'] = '请删除此用户的其他工位后添加新职位';
            return json_encode($result);
        }
        switch (input("param.authority_id")) {
            case 3:
                //申请维修工
                if (!input("?param.jiguan")) {
                    $result['msg'] = '籍贯输入错误';
                    return json_encode($result);

                }	if (!input("?param.gonling")) {
                $result['msg'] = '工龄输入错误';
                return json_encode($result);
            }

                if (!input("?param.user_skill")) {
                    $result['msg'] = '技能输入错误';
                    return json_encode($result);
                }
                if (!input("?param.names")) {
                    $result['msg'] = '工种类型输入错误';
                    return json_encode($result);
                }
                $UserModel = new UserPosition();
                //维修
                $data = $UserModel->Water_delivery_worker($user['uid'], input("param.name"), input("param.phone_number"), input("param.identity_img1"), input("param.identity_img2"), input("param.authority_id"), '维修工',input("param.names"),input("param.is_baiben"),input("param.img"),input("param.jiguan"),input("param.gonling"),input("param.user_skill"),input("param.type"),input("param.proportion"));
                break;
            case 4:
                //勘察员
                if (!input("?param.jiguan")) {
                    $result['msg'] = '籍贯输入错误';
                    return json_encode($result);

                }	if (!input("?param.gonling")) {
                $result['msg'] = '工龄输入错误';
                return json_encode($result);

            }

                $UserModel = new UserPosition();
                $data = $UserModel->Water_delivery_worker($user['uid'], input("param.name"), input("param.phone_number"), input("param.identity_img1",''), input("param.identity_img2",''), input("param.authority_id"), '勘察员','','1',input("param.img"),input("param.jiguan"),input("param.gonling"),input("param.user_skill"),input("param.type"),input("param.proportion"));
                break;
            case 5:
                //申请送水工
                $UserModel = new UserPosition();
                $data = $UserModel->Water_delivery_worker($user['uid'], input("param.name"), input("param.phone_number"), '', '', input("param.authority_id"), '送水工','','',input("param.img"));
                break;
            default:
        }

        if ($data) {
            return $this->success("申请成功");
        } else {
            return $this->fail("申请失败");
        }
    }


    /**
     * 员工管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function user_shengqing(Request $request)
    {
        $data = $request->param();

        if (empty($data['id'])) return $this->fail("用户id不能为空");
        if (empty($data['status'])) return $this->fail("status不能为空");

        $user_position  =  Db::name('user_position')->where('id',$data['id'])->find();
        if ($user_position){

            Db::startTrans();
            try {
                $user = Db::name('user')->where('uid',$user_position['user_id'])->find ();

                if ($data['status']==1){
                    Db::name('user_position')->where('id',$data['id'])->update(['is_status'=>$data['status']]);

                    Db::name('user_position')->where('id','<>',$data['id'])->where ('user_id',$user_position['user_id'])->update(['is_status'=>2]);
                    DB::name('user')->where('uid',$user_position['user_id'])
                        ->update([
                            'user_authority'=>$user_position['authority_id'],
                            'name'=>$user_position['name'],
                            'avatar'=>$user_position['img'],
                            'jiguan'=>$user_position['jiguan'],
                            'gonling'=>$user_position['gonling'],
                            'user_skill'=>$user_position['user_skill'],
                            'user_skill_name'=>$user_position['names'],
                            'user_authority_proportion_type'=>$user_position['type'],
                            'user_authority_proportion'=>$user_position['proportion'],
                            'is_baiben'=>$user_position['is_baiben'],
                            'mobile'=>$user_position['phone_number']]);
                }else{
                    Db::name('user_position')->where('id',$data['id'])->update(['is_status'=>$data['status']]);
                    DB::name('user')
                        ->where('uid',$user_position['user_id'])
                        ->update(['user_authority'=>10]);
                }
                Db::commit();

                return $this->success("成功");
            } catch (\Exception $e) {
                Db::rollback();
                return $this->fail($e->getMessage());
            }
        }else{
            return $this->fail("未查询到此用户");
        }

    }


    /**
     * 员工管理列表 - 编辑
     * @return false|string|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function up_user_auth_weixiu(Request $request)
    {
        $result['status'] = false;
        $param = $request->param();
        $user = Db::name('user')->where('uid',input("param.user_id",0))->find();
        if (!$user){
            $result['msg'] = '用户不存在';
            return json_encode($result);
        }

        switch (input("param.authority_id")) {
            case 3:
                //申请维修工
                if (!input("?param.jiguan")) {
                    $result['msg'] = '籍贯输入错误';
                    return json_encode($result);

                }

                if (!input("?param.gonling")) {
                    $result['msg'] = '工龄输入错误';
                    return json_encode($result);
                }

                if (!input("?param.user_skill")) {
                    $result['msg'] = '技能输入错误';
                    return json_encode($result);
                }
                if (!input("?param.names")) {
                    $result['msg'] = '工种类型输入错误';
                    return json_encode($result);
                }
                $UserModel = new UserPosition();
                $data = $UserModel->Water_delivery_worker($user['uid'], input("param.name"), input("param.phone_number"), input("param.identity_img1",''), input("param.identity_img2",''), input("param.authority_id"), '维修工',input("param.names"),input("param.is_baiben"),input("param.img"),input("param.jiguan"),input("param.gonling"),input("param.user_skill"),input ("param.type"),input ("param.proportion"),input ("param.id"));
                break;
            case 4:
                //勘察员
                if (!input("?param.jiguan")) {
                    $result['msg'] = '籍贯输入错误';
                    return json_encode($result);
                }
                if (!input("?param.gonling")) {
                    $result['msg'] = '工龄输入错误';
                    return json_encode($result);
                }

                $UserModel = new UserPosition();
                $data = $UserModel->Water_delivery_worker($user['uid'], input("param.name"), input("param.phone_number"), input("param.identity_img1",''), input("param.identity_img2",''), input("param.authority_id"), '勘察员','','1',input("param.img"),input("param.jiguan"),input("param.gonling"),input ("param.user_skill"),input ("param.type"),input ("param.proportion"),input ("param.id"));
                break;
            default:
        }


        if ($data) {

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param["name"]}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','员工管理列表','up_user_auth_weixiu','编辑',$param,$ip,$desc);

            return $this->success("成功");
        } else {
            return $this->fail("失败");
        }
    }


    /**
     * 员工管理列表 - 删除
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function user_shengqing_Del(Request $request)
    {
        $data = $request->param();

        if (empty($data['id'])) return $this->fail("用户id不能为空");

        $user_position  =  Db::name('user_position')->where('id',$data['id'])->find();

        if ($user_position){
            Db::startTrans();
            try {
                DB::name('user')->where('uid',$user_position['user_id'])->update(['user_authority'=>10]);
                Db::name('user_position')->where('id',$data['id'])->delete();

                Db::commit();

                $admin_id = $this->adminId;
                $ip = $request->ip();
                $desc = "-将id为{$data['id']}的数据删除.";
                SystemOperationLog::addSystemLog($admin_id,'repair','员工管理列表','user_shengqing_Del','删除',$data,$ip,$desc);

                return $this->success("成功");
            } catch (\Exception $e) {
                Db::rollback();
                return $this->fail($e->getMessage());
            }
        }else{
            return $this->fail('未查询到此用户');
        }
    }



    /**
     * 工种管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function wokr_type_list(Request $request)
    {
        $page = input('param.page', 1);
        $limit = input('param.limit', 10);
        $where=[];

        $name = input('name','');
        if (!empty($name)) $where['name']=['Like','%'.$name.'%'];

        $type = 1;
        if (input ('?type')) $type = input('type','2');
        if (!empty($type)) $where['fixed']=$type;

        $data['data'] = Db::name ('work_type')->where ($where)
            ->page ($page,$limit)
            ->order('id','desc')
            ->select();

        $data['count']= Db::name ('work_type')->where ($where)
            ->count();

        return $this->success($data);
    }


    /**
     * 工种管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableWorkType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = WorkType::enableWorkType($param);

        return $this->success($msg);
    }



    /**
     * 工种管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function wokr_type_add(Request $request)
    {
        $panm = $request->param ();
        if ($panm['name']==null) return $this->fail('name不能为空');
        if ($panm['status']==null) return $this->fail('是否前台显示分成不能为空');

        $type = 1;
        if (input ('?type')){
            $type = input('type','2');
        }
        $data['type'] = $type;
        $data['name'] = $panm['name'];
        $data['status'] = $panm['status'];
        $data['ctime'] = date ('Y-m-d H:i:s');
        $res = Db::name('work_type')->insert($data);

        return $this->success($res);
    }


    /**
     * 工具管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function wokr_type_del(Request $request)
    {
        $panm = $request->param();

        if ($panm['id']==null) return $this->fail('id不能为空');

        $work_type = Db::name('work_type')->where('id',$panm['id'])->find ();
        if ($work_type['type']==2){
            $data = Db::name('tool')->where('type',2)->where ('types',$panm['id'])->select();
            if (count($data)==0){
                $res = Db::name('work_type')->where ('id',$panm['id'])->delete();
            }else{
                return $this->fail('请先更改工具后删除');
            }
        }else{
            $data = 0; //Db::name('user')->where('user_skill_name', $panm['id'])->select();
            if (count ($data)==0){
                $res = Db::name('work_type')->where('id',$panm['id'])->delete();
            }else{
                return $this->fail('请先更改员工工种后删除');
            }
        }

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$panm['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','工具管理列表','wokr_type_del','删除',$panm,$ip,$desc);

        return $this->success($res);
    }



    /**
     * 工具管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function wokr_type_up(Request $request)
    {
        $panm = $request->param();

        if ($panm['name'] == null) return $this->fail('name不能为空');
        if ($panm['status']==null) return $this->fail('是否前台显示分成不能为空');

        $type = 1;
        if (input ('?type')){
            $type = input ('type','2');
        }
        $data['type']=$type;

        $data['name']=$panm['name'];
        $data['status']=$panm['status'];
        $res= Db::name('work_type')->where ('id',$panm['id'])->update($data);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$panm['id']}的数据编辑为：名称：{$panm['name']}.";
        SystemOperationLog::addSystemLog($admin_id,'repair','工具管理列表','wokr_type_up','编辑',$panm,$ip,$desc);

        return $this->success($res);
    }




    /**
     * 维修项目分类管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getRepairCatList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = RepairCat::getRepairCatList($param);

        return $this->success($data);
    }


    /**
     * 获取分类列表
     * @param Request $request
     * @return mixed
     */
    public function getRepairCatData(Request $request)
    {
        $param = $request->param();
        $id = $param["id"] ?? 0;
        $data = RepairCat::getRepairCatData($id);

        return $this->success($data);
    }


    /**
     * 获取省市区街道
     * @param Request $request
     * @return mixed
     */
    public function getRepairAreaData(Request $request)
    {
        $param = $request->param();
        $id = $param["id"] ?? 0;
        $data = CityArea::getRepairAreaData($id);

        return $this->success($data);
    }


    /**
     * 维修项目分类管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteRepairCat(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RepairCat::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','维修项目分类管理列表','deleteRepairCat','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 维修项目分类管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateRepairCat(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['name'])) return $this->fail('name不能为空');

        $res = RepairCat::updateRepairCat($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类名称：{$param['name']}.";
        SystemOperationLog::addSystemLog($admin_id,'repair','维修项目分类管理列表','updateRepairCat','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
    }


    /**
     * 添加项目分类
     * @param Request $request
     * @return mixed
     */
    public function addRepairCat(Request $request)
    {
        $param = $request->param();
        if(empty($param['name'])) return $this->fail('name不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RepairCat::addRepairCat($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }



    /**
     * 维修项目分类管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableRepairCat(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RepairCat::enableRepairCat($param);

        return $this->success($msg);
    }


    /**
     * 装修质保管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConstructionList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = Construction::getConstructionList($param);

        return $this->success($data);
    }



    /**
     * 装修质保管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteConstruction(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = Construction::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','deleteConstruction','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 装修质保管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateConstruction(Request $request)
    {
        /*
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['name'])) return $this->fail('name不能为空');
        if(empty($param['user_id'])) return $this->fail('user_id关联编码不能为空');

        $user_find = User::where("uid", $param['user_id'])->find() ?? [];
        if(empty($user_find)) return $this->fail('未查询到此用户');


        $res = Construction::updateConstruction($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param['name']}.";
        SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','updateConstruction','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
        */


        $panm = $request->param();
        if (empty($panm['id'])) return $this->fail('id不能为空');
        $data = json_decode($panm['data'],true);
        if (empty($data['user_id'])) return $this->fail('user_id关联编码不能为空');

        unset($data['id']);
        unset($data['status_text']);

        $data['phone'] = $data['user_id'];
        $user_find = User::where("uid", $data['user_id'])->find() ?? [];
        //if(empty($user_find)) return $this->fail('未查询到此用户');

        $category_id = '';
        if(!empty($data["category_id"])){
            if(is_array($data["category_id"])){
                $cate_id_data = $data["category_id"];
                $category_id = implode(",", $cate_id_data);
            }else{
                $category_id = $data["category_id"];
            }
        }
        $data["category_id"] = $category_id;
        $data["cat"] = $category_id;

        if(!empty($data["area_ids"])){
            $data["province"] = 1;
            $data["city"] = $data["area_ids"][0] ?? '';
            $data["district"] = $data["area_ids"][1] ?? '';
            $data["street"] = $data["area_ids"][2] ?? '';
        }

        unset($data['mobile']);
        unset($data['area_ids']);

        $res = Db::name('construction')->where('id',$panm['id'])->update($data);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$panm['id']}的数据编辑为：名称：{$data['name']}.";
        SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','updateConstruction','编辑',$panm,$ip,$desc);

        return $this->success('编辑成功');
    }


    /**
     * 装修质保管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addConstruction(Request $request)
    {
        /*
        $param = $request->param();
        if(empty($param['name'])) return $this->fail('name不能为空');
        if(empty($param['user_id'])) return $this->fail('user_id关联编码不能为空');

        $user_find = User::where("uid", $param['user_id'])->find() ?? [];
        if(empty($user_find)) return $this->fail('未查询到此用户');

        $param['user_name'] = $user_find["nickname"] ?? '';
        $param["admin_id"] = $this->adminId;

        $param['ctime']=date('Y-m-d H:i:s');

        unset($param['mobile']);
        $res = Db::name('construction')->insert($param);
        //$res = Construction::addConstruction($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
        */


        $panm = $request->param();
        $data = json_decode($panm['data'],true);

        if (empty($data['user_id'])) return $this->fail('user_id关联编码不能为空');

        $data['phone'] = $data['user_id'];
        $user_find = User::where("phone", $data['user_id'])->find() ?? [];   //uid
        if(empty($user_find)) return $this->fail('未查询到此用户');

        $data['user_id'] = $user_find['uid'] ?? '';
        $data['uid'] = $user_find['uid'] ?? '';
        $data['user_name'] = $user_find['nickname'] ?? ($user_find['real_name'] ?? '');
        $data['ctime'] = date('Y-m-d H:i:s');

        $category_id = '';
        if(!empty($data["category_id"])){
            if(is_array($data["category_id"])){
                $cate_id_data = $data["category_id"];
                $category_id = implode(",", $cate_id_data);
            }else{
                $category_id = $data["category_id"];
            }
        }
        $data["category_id"] = $category_id;
        $data["cat"] = $category_id;

        if(!empty($data["area_ids"])){
            $data["province"] = '北京市';
            $data["city"] = Construction::getCityAreaName($data["area_ids"][0] ?? '');
            $data["district"] = Construction::getCityAreaName($data["area_ids"][1] ?? '');
            $data["street"] = Construction::getCityAreaName($data["area_ids"][2] ?? '');
        }

        unset($data['mobile']);
        ////unset($data['area_ids']);

        $data['area_ids'] = implode(",",$data['area_ids']);
        $data = Db::name('construction')->insert($data);

        return $this->success('success');
    }



    /**
     * 装修质保管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableConstruction(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = Construction::enableConstruction($param);

        return $this->success($msg);
    }





    public function construction_list(Request $request)
    {
        $panm = $request->param();
        if ($panm['page']==null) return $this->fail("分页不能为空");
        if ($panm['limit']==null) return $this->fail("分页不能为空");

        $res['data'] = Db::name('construction')->page($panm['page'],$panm['limit'])->order ('id','desc')->select();
        $res['count'] = Db::name('construction')->count();

        return $this->success($res);
    }




    /**
     * 打卡管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getUserWorkList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = UserWork::getUserWorkList($param);

        return $this->success($data);
    }



    /**
     * 打卡管理列表 - 查看
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function detailUserWork(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = UserWork::detailUserWork($param);

        return $this->success($detail ? $detail->toArray() : []);
    }



    /**
     * 打卡管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function delUserWork(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = UserWork::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','打卡管理列表','delUserWork','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }





    /**
     * 勘察员管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSurveyorList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = SurveyorService::getSurveyorList($param);

        return $this->success($data);
    }



    /**
     * 勘察员管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteSurveyor(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = SurveyorService::where("id", $param['id'])->update(['is_del'=>1]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','勘察员管理列表','deleteSurveyor','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 勘察员管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateSurveyor(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['phone'])) return $this->fail('phone不能为空');
            if(empty($param['nickname'])) return $this->fail('nickname不能为空');

            $res = SurveyorService::updateSurveyor($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param['nickname']}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','updateConstruction','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 勘察员管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addSurveyor(Request $request)
    {
        try {
            $param = $request->param();
            if (empty($param['phone'])) return $this->fail('phone不能为空');

            $param["admin_id"] = $this->adminId;
            $res = SurveyorService::addConstruction($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "$admin_id-添加了手机号为{$param['phone']}的勘察员.";
            SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','addSurveyor','添加',$param,$ip,$desc);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }



    /**
     * 勘察员管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableSurveyor(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = SurveyorService::enableSurveyor($param);

        return $this->success($msg);
    }


    /**
     * 维修工管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getRepairServiceList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = RepairService::getRepairServiceList($param);

        return $this->success($data);
    }



    /**
     * 维修工管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteRepairService(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RepairService::where("id", $param['id'])->update(['is_del'=>1]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','维修工管理列表','deleteRepairService','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 维修工管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateRepairService(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['phone'])) return $this->fail('phone不能为空');
            if(empty($param['nickname'])) return $this->fail('nickname不能为空');

            $res = RepairService::updateRepairService($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param['nickname']}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','装修质保管理列表','updateConstruction','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 维修工管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRepairService(Request $request)
    {
        try {
            $param = $request->param();
            if (empty($param['phone'])) return $this->fail('phone不能为空');

            $param["admin_id"] = $this->adminId;
            $res = RepairService::addRepairService($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "$admin_id-添加了手机号为{$param['phone']}的维修工.";
            SystemOperationLog::addSystemLog($admin_id,'repair','维修工管理列表','addRepairService','添加',$param,$ip,$desc);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 维修工管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableRepairService(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RepairService::enableRepairService($param);

        return $this->success($msg);
    }



    /**
     * 代购管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getMaterialDataList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = AuxiliaryMaterialData::getMaterialDataList($param);

        return $this->success($data);
    }



    /**
     * 代购管理列表 - 查看
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function detailMaterialData(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = AuxiliaryMaterialData::detailMaterialData($param);

        return $this->success($detail ? $detail->toArray() : []);
    }




    /**
     * 维修管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getMaintenanceList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = Maintenance::getMaintenanceList($param);

        return $this->success($data);
    }



    /**
     * 维修管理列表 - 查看
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function detailMaintenance(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $detail = Maintenance::detailMaintenance($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 维修管理列表 - 审核按钮
     * @return void
     */
    public function auditMaintenance(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['audit_state'])) return $this->fail('audit_state不能为空');
        $msg = "通过";
        if($param["audit_state"] == 3){
            if(empty($param['reason'])) return $this->fail('reason原因描述不能为空');
            $msg = "不通过";
        }

        $res = Maintenance::auditMaintenance($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据审核为：{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'repair','维修管理列表','auditMaintenance','审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }




    /**
     * 维修单管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getMaintenanceOrderList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = MaintenanceOrder::getMaintenanceOrderList($param);

        return $this->success($data);
    }



    /**
     * 维修单管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteMaintenanceOrder(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = MaintenanceOrder::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','维修单管理列表','deleteMaintenanceOrder','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 维修单管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateMaintenanceOrder(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['order_id'])) return $this->fail('order_id不能为空');

            $res = MaintenanceOrder::updateMaintenanceOrder($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：订单号：{$param['order_id']}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','维修单管理列表','updateMaintenanceOrder','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 维修单管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addMaintenanceOrder(Request $request)
    {
        try {
            $param = $request->param();
            if (empty($param['phone'])) return $this->fail('phone不能为空');

            $param["admin_id"] = $this->adminId;
            $res = MaintenanceOrder::addRepairService($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "$admin_id-添加了手机号为{$param['phone']}的维修工.";
            SystemOperationLog::addSystemLog($admin_id,'repair','维修工管理列表','addRepairService','添加',$param,$ip,$desc);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 维修单管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableMaintenanceOrder(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = MaintenanceOrder::enableMaintenanceOrder($param);

        return $this->success($msg);
    }



    /**
     * 勘察员绩效管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSurveyorExamineList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取勘察员ids
        $ids = SurveyorService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("b.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSurveyorExamineList($param, $ids);

        return $this->success($data);
    }



    /**
     * 勘察员绩效管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteSurveyorExamine(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = WorkerExamine::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','勘察员绩效管理列表','deleteSurveyorExamine','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 勘察员绩效管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateSurveyorExamine(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['order_id'])) return $this->fail('order_id不能为空');

            $res = WorkerExamine::updateSurveyorExamine($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：订单号：{$param['order_id']}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','勘察员绩效管理列表','updateSurveyorExamine','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 勘察员绩效管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addSurveyorExamine(Request $request)
    {
        try {
            $param = $request->param();
            if (empty($param['user_id'])) return $this->fail('user_id不能为空');
            if (empty($param['single_quantity'])) return $this->fail('single_quantity不能为空');
            if (empty($param['performance'])) return $this->fail('performance不能为空');
            if (empty($param['Bad'])) return $this->fail('Bad不能为空');
            if (empty($param['esteem'])) return $this->fail('esteem不能为空');

            $param["admin_id"] = $this->adminId;
            $res = WorkerExamine::addSurveyorExamine($param);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 勘察员绩效管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableSurveyorExamine(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = WorkerExamine::enableSurveyorExamine($param);

        return $this->success($msg);
    }


    /**
     * 维修工绩效管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getRepairExamineList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取维修工ids
        $ids = RepairService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("b.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSurveyorExamineList($param, $ids);

        return $this->success($data);
    }


    /**
     * 送水工绩效管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getWaterExamineList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取送水工ids
        $ids = DeliveryService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("b.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSurveyorExamineList($param, $ids);

        return $this->success($data);
    }


    /**
     * 版本信息管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConfigAboutList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = ConfigAbout::getConfigAboutList($param);

        return $this->success($data);
    }



    /**
     * 版本信息管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteConfigAbout(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = ConfigAbout::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'about','版本信息管理列表','deleteConfigAbout','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 版本信息管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateConfigAbout(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['content'])) return $this->fail('content不能为空');
            if(empty($param['desc'])) return $this->fail('desc不能为空');

            $res = ConfigAbout::updateConfigAbout($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param['content']}.";
            SystemOperationLog::addSystemLog($admin_id,'about','版本信息管理列表','updateConfigAbout','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 版本信息管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addConfigAbout(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['content'])) return $this->fail('content不能为空');
            if(empty($param['desc'])) return $this->fail('desc不能为空');

            $param["admin_id"] = $this->adminId;
            $res = ConfigAbout::addConfigAbout($param);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }



    /**
     * 版本信息管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableConfigAbout(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = ConfigAbout::enableConfigAbout($param);

        return $this->success($msg);
    }



    /**
     * 第三方厂商维修工管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getCatUserList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = RepairCatUser::getCatUserList($param);

        return $this->success($data);
    }



    /**
     * 第三方厂商维修工管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteCatUser(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RepairCatUser::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','第三方厂商维修工管理列表','deleteCatUser','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 第三方厂商维修工管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateCatUser(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['rs_id'])) return $this->fail('rs_id不能为空');
        if(empty($param['cat_id'])) return $this->fail('cat_id不能为空');

        try {
            $res = RepairCatUser::updateCatUser($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：分类id：{$param['cat_id']}.";
            SystemOperationLog::addSystemLog($admin_id, 'repair', '第三方厂商维修工管理列表', 'updateCatUser', '编辑', $param, $ip, $desc);

            if ($res >= 0) return $this->success('编辑成功');
            return $this->fail('编辑失败');
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 添加第三方厂商维修工
     * @param Request $request
     * @return mixed
     */
    public function addCatUser(Request $request)
    {
        $param = $request->param();
        if(empty($param['rs_id'])) return $this->fail('rs_id不能为空');
        if(empty($param['cat_id'])) return $this->fail('cat_id不能为空');

        try {
            $param["admin_id"] = $this->adminId;
            $res = RepairCatUser::addCatUser($param);
            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 第三方厂商维修工管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableCatUser(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RepairCatUser::enableCatUser($param);

        return $this->success($msg);
    }


    /**
     * 获取维修工列表
     * @param Request $request
     * @return mixed
     */
    public function getRepairUserList(Request $request)
    {
        $param = $request->post();

        $data = RepairService::getRepairUserList($param);

        return $this->success($data);
    }



    /**
     * 勘察员绩效汇总列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSummaryExamineList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取勘察员ids
        $ids = SurveyorService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("a.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSummaryExamineList($param, $ids);

        return $this->success($data);
    }




    /**
     * 维修工绩效汇总列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSummaryRepairList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取维修工ids
        $ids = RepairService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("a.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSummaryRepairList($param, $ids);

        return $this->success($data);
    }



    /**
     * 送水工绩效汇总列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSummaryWaterList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        //获取送水工ids
        $ids = DeliveryService::alias("a")
            ->where("a.is_del", 0)
            ->where(function ($query) use ($param){
                if(!empty($param["nickname"])) $query->where("a.nickname", "like", '%'.$param["nickname"].'%');
                if(!empty($param["phone"])) $query->where("b.phone", "like", '%'.$param["phone"].'%');
            })
            ->join('user b', 'a.uid=b.uid','left')
            ->column("a.uid") ?? [];
        if(empty($ids)) return $this->success([]);

        $data = WorkerExamine::getSummaryWaterList($param, $ids);

        return $this->success($data);
    }




    /**
     * 建议管理列表
     * @param Request $request
     * @return mixed
     */
    public function getSuggestionList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RepairSuggestion::getSuggestionList($param);

        return $this->success($data);
    }


    /**
     * 咨询管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getRepairConsultList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = RepairConsult::getRepairConsultList($param);

        return $this->success($data);
    }



    /**
     * 咨询管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteRepairConsult(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RepairConsult::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'repair','咨询管理列表','deleteRepairConsult','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }




    /**
     * 咨询管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateRepairConsult(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['id'])) return $this->fail('id不能为空');
            if(empty($param['title'])) return $this->fail('title不能为空');

            $res = RepairConsult::updateRepairConsult($param);

            $admin_id = $this->adminId;
            $ip = $request->ip();
            $desc = "-将id为{$param['id']}的数据编辑为：名称：{$param['title']}.";
            SystemOperationLog::addSystemLog($admin_id,'repair','咨询管理列表','updateRepairConsult','编辑',$param,$ip,$desc);

            if ($res >= 0)  return $this->success('编辑成功');
            return $this->fail('编辑失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 咨询管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRepairConsult(Request $request)
    {
        try {
            $param = $request->param();
            if(empty($param['content'])) return $this->fail('content不能为空');
            if(empty($param['desc'])) return $this->fail('desc不能为空');

            $param["admin_id"] = $this->adminId;
            $res = RepairConsult::addRepairConsult($param);

            if ($res > 0) {
                return $this->success('success');
            }
            return $this->fail('添加失败');

        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }



    /**
     * 咨询管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableRepairConsult(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RepairConsult::enableRepairConsult($param);

        return $this->success($msg);
    }




}